/*************************************************
Author: Aven
Date: 2/25/2013
Description:
Notes:
*************************************************/

#ifndef __CVipConfig_h__
#define __CVipConfig_h__

#include "CTArray.h"
#include "CVipDef.h"

class CVipConfig;

//vip奖励配置
class CVipAwardConfigData
{
    friend class CVipConfig;
public:
    CVipAwardConfigData()
        :_bHasConfig(false)
    {
        _iVipLevel = 0;
        _aTAwards.Clear();
    }

    virtual ~CVipAwardConfigData()
    {
    }

    struct TAward
    {
        int iAwardItemType;
        int iAwardItemId;
        int iAwardNum;
    };

    void Clear() {_bHasConfig = false;}

    bool HasConfig() const {return _bHasConfig;}

public:
    bool _bHasConfig;

    int _iVipLevel;           //vip 等级

    CTLib::CTArray<TAward, MAX_VIP_AWARD_NUM> _aTAwards; //VIP奖励, 最多5个数量
};

class CVipPayGoldConfig
{
public:
    CVipPayGoldConfig()
        :_bHasConfig(false)
    {
        _iVipLevel = 0;
        _iNeedGold = 0;
    }

    virtual ~CVipPayGoldConfig()
    {
    }

    void Clear() {_bHasConfig = false;}

    bool HasConfig() const {return _bHasConfig;}

public:
    bool _bHasConfig;

    int _iVipLevel;           //vip 等级
    int _iNeedGold;           //需要满足金币数
};

class CVipExtNumConfig
{
public:
    CVipExtNumConfig()
        :_bHasConfig(false)
    {
        _iVipLevel = 0;
        _iModuleId = 0;
        _iModuleExtNum = 0;
    }

    virtual ~CVipExtNumConfig()
    {
    }

    void Clear() {_bHasConfig = false;}

    bool HasConfig() const {return _bHasConfig;}

public:
    bool _bHasConfig;

    int _iModuleId;           //目标模块id
    int _iVipLevel;           //vip 等级
    int _iModuleExtNum;       //付费目标次数
};

//vip配置数据
class CVipConfig
{
public:
    CVipConfig()
    {
    }

    virtual ~CVipConfig()
    {
    }

    int Init();

    int GetVipLevelAwardConfig(int iVipLevel, CVipAwardConfigData& stData);
    int AddVipLevelAwardConfig(CVipAwardConfigData& stData);

    int GetVipDailyAwardConfig(int iVipLevel, CVipAwardConfigData& stData);
    int AddVipDailyAwardConfig( CVipAwardConfigData& stData );

    int GetVipPayGoldConfig(int iVipLevel, CVipPayGoldConfig& stData);
    int AddVipPayGoldConfig( CVipPayGoldConfig& stData );

    int GetVipExtNumConfig(int iVipLevel, int iModuleId, CVipExtNumConfig& stData);
    int AddVipExtNumConfig( CVipExtNumConfig& stData );

private:
    CTLib::CTArray<CVipAwardConfigData, MAX_VIP_LEVEL+1>           _astVipDailyAwardConfigs;   //vip当阶每日奖励
    CTLib::CTArray<CVipAwardConfigData, MAX_VIP_LEVEL+1>        _astVipLevelAwardConfigs;      //vip升级奖励
    CTLib::CTArray<CVipPayGoldConfig, MAX_VIP_LEVEL+1>        _astVipPayGoldConfigs;      //vip充值金币配置
    CTLib::CTArray<CVipExtNumConfig, MAX_VIP_MODULE_NUMS+1>        _astVipModuleExtConfigs;      //vip付费目标次数配置
};

class CYellowGiftConfig
{
public:
    CYellowGiftConfig()
    {
        _astDayGiftID.Clear();
        _astLevelGiftID.Clear();
        _iNewbieGiftID = 0;
    }

    int SetDayGiftID(int iYellowLevel, int iGiftID)
    {
        if (iYellowLevel <= 0 || iYellowLevel > MAX_YELLOW_LEVEL)
        {
            CT_ERROR(("%d", iYellowLevel));
            return RET_SYS_ERROR;
        }

        while (_astDayGiftID.Size() <= iYellowLevel - 1)
        {
            _astDayGiftID.AddOneItem(0);
        }

        _astDayGiftID[iYellowLevel - 1] = iGiftID;
        return 0;
    }

    int GetDayGiftID(int iYellowLevel)
    {
        if (iYellowLevel <= 0 || iYellowLevel > MAX_YELLOW_LEVEL)
        {
            CT_WARNING(("%d", iYellowLevel));
            return 0;
        }

        if (_astDayGiftID.Size() <= iYellowLevel - 1)
        {
            CT_WARNING(("%d", iYellowLevel));
            return 0;
        }

        return _astDayGiftID[iYellowLevel - 1];
    }

    int SetYearDayGiftID(int iYellowLevel, int iGiftID)
    {
        if (iYellowLevel <= 0 || iYellowLevel > MAX_YELLOW_LEVEL)
        {
            CT_ERROR(("%d", iYellowLevel));
            return RET_SYS_ERROR;
        }

        while (_astYearDayGiftID.Size() <= iYellowLevel - 1)
        {
            _astYearDayGiftID.AddOneItem(0);
        }

        _astYearDayGiftID[iYellowLevel - 1] = iGiftID;
        return 0;
    }

    int GetYearDayGiftID(int iYellowLevel)
    {
        if (iYellowLevel <= 0 || iYellowLevel > MAX_YELLOW_LEVEL)
        {
            CT_WARNING(("%d", iYellowLevel));
            return 0;
        }

        if (_astYearDayGiftID.Size() <= iYellowLevel - 1)
        {
            CT_WARNING(("%d", iYellowLevel));
            return 0;
        }

        return _astYearDayGiftID[iYellowLevel - 1];
    }

    int SetLevelGiftID(int iLevelIndex, int iGiftID)
    {
        //iLevelIndex表示 level / 10
        if (iLevelIndex <= 0 || iLevelIndex > MAX_YELLOW_LEVEL_GIFT_COUNT)
        {
            CT_ERROR(("%d", iLevelIndex));
            return RET_SYS_ERROR;
        }

        while (_astLevelGiftID.Size() <= iLevelIndex - 1)
        {
            _astLevelGiftID.AddOneItem(0);
        }

        _astLevelGiftID[iLevelIndex - 1] = iGiftID;
        return 0;
    }

    int GetLevelGiftID(unsigned short usLevel)
    {
        int iLevelIndex = usLevel / 10;
        if (iLevelIndex <= 0 || iLevelIndex > MAX_YELLOW_LEVEL_GIFT_COUNT)
        {
            return 0;
        }

        if (_astLevelGiftID.Size() <= iLevelIndex - 1)
        {
            CT_WARNING(("%d", iLevelIndex));
            return 0;
        }

        return _astLevelGiftID[iLevelIndex - 1];
    }

    void SetNewbieGiftID(int iGiftID)
    {
        _iNewbieGiftID = iGiftID;
    }

    int GetNewbieGiftID()
    {
        return _iNewbieGiftID;
    }

    unsigned short _usYellowMount;   //黄钻坐骑
private:
    CTLib::CTArray<int, MAX_YELLOW_LEVEL> _astDayGiftID; //黄钻每日礼包，以黄钻等级为下标，1级下标是0
    CTLib::CTArray<int, MAX_YELLOW_LEVEL> _astYearDayGiftID; //年费黄钻每日礼包，以黄钻等级为下标，1级下标是0
    CTLib::CTArray<int, MAX_YELLOW_LEVEL_GIFT_COUNT> _astLevelGiftID; //黄钻等级礼包，以等级/10为下标，10级下标是0
    int _iNewbieGiftID;         //黄钻新手礼包
};

class CBlueGiftConfig //蓝钻礼包配置
{
public:
    CBlueGiftConfig()
    {
        _astDayGiftID.Clear();
        _astLevelGiftID.Clear();
        _iNewbieGiftID = 0;
        _ast3366DayGiftID.Clear();
    }

    int SetDayGiftID(int iBlueLevel, int iGiftID)
    {
        if (iBlueLevel <= 0 || iBlueLevel > MAX_YELLOW_LEVEL)
        {
            CT_ERROR(("%d", iBlueLevel));
            return RET_SYS_ERROR;
        }

        while (_astDayGiftID.Size() <= iBlueLevel - 1)
        {
            _astDayGiftID.AddOneItem(0);
        }

        _astDayGiftID[iBlueLevel - 1] = iGiftID;
        return 0;
    }

    int GetDayGiftID(int iBlueLevel)
    {
        if (iBlueLevel <= 0 || iBlueLevel > MAX_YELLOW_LEVEL)
        {
            CT_WARNING(("%d", iBlueLevel));
            return 0;
        }

        if (_astDayGiftID.Size() <= iBlueLevel - 1)
        {
            CT_WARNING(("%d", iBlueLevel));
            return 0;
        }

        return _astDayGiftID[iBlueLevel - 1];
    }

    int SetYearDayGiftID(int iBlueLevel, int iGiftID)
    {
        if (iBlueLevel <= 0 || iBlueLevel > MAX_YELLOW_LEVEL)
        {
            CT_ERROR(("%d", iBlueLevel));
            return RET_SYS_ERROR;
        }

        while (_astYearDayGiftID.Size() <= iBlueLevel - 1)
        {
            _astYearDayGiftID.AddOneItem(0);
        }

        _astYearDayGiftID[iBlueLevel - 1] = iGiftID;
        return 0;
    }

    int GetYearDayGiftID(int iBlueLevel)
    {
        if (iBlueLevel <= 0 || iBlueLevel > MAX_YELLOW_LEVEL)
        {
            CT_WARNING(("%d", iBlueLevel));
            return 0;
        }

        if (_astYearDayGiftID.Size() <= iBlueLevel - 1)
        {
            CT_WARNING(("%d", iBlueLevel));
            return 0;
        }

        return _astYearDayGiftID[iBlueLevel - 1];
    }

    int SetLevelGiftID(int iLevelIndex, int iGiftID)
    {
        //iLevelIndex表示 level / 10
        if (iLevelIndex <= 0 || iLevelIndex > MAX_YELLOW_LEVEL_GIFT_COUNT)
        {
            CT_ERROR(("%d", iLevelIndex));
            return RET_SYS_ERROR;
        }

        while (_astLevelGiftID.Size() <= iLevelIndex - 1)
        {
            _astLevelGiftID.AddOneItem(0);
        }

        _astLevelGiftID[iLevelIndex - 1] = iGiftID;
        return 0;
    }

    int GetLevelGiftID(unsigned short usLevel)
    {
        int iLevelIndex = usLevel / 10;
        if (iLevelIndex <= 0 || iLevelIndex > MAX_YELLOW_LEVEL_GIFT_COUNT)
        {
            return 0;
        }

        if (_astLevelGiftID.Size() <= iLevelIndex - 1)
        {
            CT_WARNING(("%d", iLevelIndex));
            return 0;
        }

        return _astLevelGiftID[iLevelIndex - 1];
    }

    void SetNewbieGiftID(int iGiftID)
    {
        _iNewbieGiftID = iGiftID;
    }

    int GetNewbieGiftID()
    {
        return _iNewbieGiftID;
    }

    int Get3366DayGiftID(unsigned char uc3366Level)
    {
        if (uc3366Level >= 26)
        {
            return _ast3366DayGiftID[MAX_3366_LEVEL_COUNT - 1];
        }
        else if (uc3366Level >= 21)
        {
            return _ast3366DayGiftID[MAX_3366_LEVEL_COUNT - 2];
        }
        else if (uc3366Level >= 16)
        {
            return _ast3366DayGiftID[MAX_3366_LEVEL_COUNT - 3];
        }
        else if (uc3366Level >= 11)
        {
            return _ast3366DayGiftID[MAX_3366_LEVEL_COUNT - 4];
        }
        else if (uc3366Level >= 6)
        {
            return _ast3366DayGiftID[MAX_3366_LEVEL_COUNT - 5];
        }
        else if (uc3366Level >= 1)
        {
            return _ast3366DayGiftID[MAX_3366_LEVEL_COUNT - 6];
        }

        return 0;
    }

    unsigned short _usBlueMount;   //蓝钻坐骑
public:
    CTLib::CTArray<int, MAX_3366_LEVEL_COUNT> _ast3366DayGiftID; //3366每日礼包配置
    int _iSuperVipGiftID;       //蓝钻豪华礼包

private:
    CTLib::CTArray<int, MAX_YELLOW_LEVEL> _astDayGiftID; //蓝钻每日礼包，以蓝钻等级为下标，1级下标是0
    CTLib::CTArray<int, MAX_YELLOW_LEVEL> _astYearDayGiftID; //年费蓝钻每日礼包，以蓝钻等级为下标，1级下标是0
    CTLib::CTArray<int, MAX_YELLOW_LEVEL_GIFT_COUNT> _astLevelGiftID; //蓝钻等级礼包，以等级/10为下标，10级下标是0
    int _iNewbieGiftID;         //蓝钻新手礼包
};

#endif // __CVipConfig_h__
